<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/8/7
 * Time: 17:46
 */

namespace app\models;

use Yii;
use yii\web\UploadedFile;


class Upload extends \yii\db\ActiveRecord
{
    /**
     * @var UploadedFile|Null file attribute
     */
    public $file;
    /**
     * @return array the validation rules.
     */
    public function rules(){
        return [
            [['image'],'file','skipOnEmpty' => false,'checkExtensionByMimeType' => false,'extensions' => 'jpg,jpeg,png']
        ];
    }


    public function upload(){
        if($this->validate()){
            $this->image->saveAs('uploads/'.$this->image->baseName.'.'.$this->image->extension);
            return true;
        }else{
            return false;
        }
    }




}